package com.litchi.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.lib.uil.ToastUtils;
import com.litchi.R;
import com.litchi.activity.BrandStoryActivity;
import com.litchi.activity.MainActivity;
import com.litchi.activity.ShakeActivity;
import com.litchi.activity.WebActivity;

/**
 * A simple {@link android.support.v4.app.Fragment} subclass.
 * 
 */
public class FindFragment extends Fragment implements OnClickListener {

	private View layout;
	private Context mContext;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		if (layout != null) {
			// 防止多次new出片段对象，造成图片错乱问题
			return layout;
		}
		layout = inflater.inflate(R.layout.fragment_find, container, false);
		layout.findViewById(R.id.layout_QR).setOnClickListener(this);
		layout.findViewById(R.id.layout_shake).setOnClickListener(this);
		layout.findViewById(R.id.layout_around).setOnClickListener(this);
		layout.findViewById(R.id.layout_activity).setOnClickListener(this);
		layout.findViewById(R.id.layout_story).setOnClickListener(this);
		mContext = getActivity();
		return layout;
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		// 将layout从父组件中移除
		ViewGroup parent = (ViewGroup) layout.getParent();
		parent.removeView(layout);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.layout_QR: // 二维码扫描

			((MainActivity) getActivity()).scanQRCode();

			break;

		case R.id.layout_shake: // 摇一摇
			startActivity(new Intent(getActivity(), ShakeActivity.class));
			break;
		case R.id.layout_around: // 发现周边
			Intent intent = new Intent(getActivity(), WebActivity.class);
			intent.putExtra("url","http://yuntu.amap.com/share/VVvIfa");
			startActivity(intent);
			break;
		case R.id.layout_story: // 品牌故事
			Intent intent2 = new Intent(getActivity(), BrandStoryActivity.class);
			intent2.putExtra("direction", 7);
			startActivity(intent2);
			break;
		case R.id.layout_activity: // 活动
			ToastUtils.showToast(mContext, "敬请期待...");
			break;

		default:
			break;
		}
	}

}
